﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.Mtool.FSM
{
    public class TokenManager
    {
        private static Dictionary<string, ActionImpl> defMap = new Dictionary<string, ActionImpl>();
        
        public static ActionImpl GetDefinition(string name)
        {
            if (!defMap.ContainsKey(name)) return null;
            // make a copy to keep the definition safe
            return defMap[name].GetCopy();
        }

        public static bool SetDefinition(string name, ActionImpl impl)
        {
            // duplicated
            if (defMap.ContainsKey(name)) return false;

            defMap[name] = impl;
            return true;
        }

        public static void DeleteDefinition(string name)
        {
            defMap.Remove(name);
        }

        public static void Reset()
        {
            defMap.Clear();        
        }
    }
}
